﻿using PlutoStudio.Net.Tcp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PlutoStudio.Net.Server
{
    public class NetService<TContext> where TContext:NetContext
    {
        private TcpListener listener;

        public NetService()
        {
            listener = new TcpListener();
            listener.Accepted += (o, e) =>
            {
                var client = e.TcpClient;
                var context = Activator.CreateInstance(typeof(TContext),client) as TContext;
                context.BeginProcess();
            };
        }

        public void Start()
        {
            listener.StartAccept();
        }

        public void Stop()
        {
            listener.Stop();
        }
    }

}
